package com.zxk.version2.consumer;


import com.zxk.version2.api.UserService;
import com.zxk.version2.core.User;

import java.io.*;
import java.net.Socket;
import java.util.Random;

/**
 * @author 朱小康
 */
public class RpcClient {
    public static void main(String[] args) {
        //建立socket链接
        try {
            ClientProxy clientProxy = new ClientProxy("127.0.0.1",8081);
            UserService userService = clientProxy.getProxy(UserService.class);


            User userByUserId = userService.getUserByUserId(10);
            System.out.println("从服务端得到的user为：" + userByUserId);
            // 服务的方法2
            User user = User.builder().userName("张三").id(100).sex(true).build();
            Integer integer = userService.insertUser(user);
            System.out.println("向服务端插入数据："+integer);

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("出现异常");
        }
    }
}
